import Taro from '@tarojs/taro'

import {postJSON} from '../utils'
import apiObj from '../api'
import {CREATE_TOPIC} from '../constants/createTopic'

/**
 * action creator
 */
export const createTopic = () => {
  return {
    type: CREATE_TOPIC
  }
}

/**
 * dispatch action
 * @param {*} params 
 */
export async function createTopicAction(params){
  let result = await postJSON(apiObj.createTopic, params)
  if(result && result.data && result.data.success){
    return result.data
  }else{
    Taro.showToast({title: '发布话题失败!', icon: 'none'})
  }
}